package com.drools.drools.juecebiao;

import com.drools.drools.BaseTest;
import com.drools.drools.model.Person;
import org.drools.decisiontable.InputType;
import org.drools.decisiontable.SpreadsheetCompiler;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.internal.io.ResourceFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * User: mishuai
 * Date: 2019-05-11
 * Time: 21:30
 * Des:
 */
public class JueCeTable extends BaseTest{

    @Test
    public void test() throws FileNotFoundException {
        File file=new File("D:\\decision.xls");
        InputStream inputStream=new FileInputStream(file);
        SpreadsheetCompiler compiler=new SpreadsheetCompiler();
        String drl=compiler.compile(inputStream, InputType.XLS);
        System.out.println(drl);
        KieSession kieSession=this.getKieSessionBySessionName("function-rules");
        Person person=new Person(21);
        kieSession.insert(person);
        kieSession.fireAllRules();
        kieSession.dispose();
    }

    @Test
    public void test2() throws FileNotFoundException {

        SpreadsheetCompiler compiler=new SpreadsheetCompiler();
        String drl=compiler.compile(ResourceFactory.newClassPathResource("decision.xls"), InputType.XLS);
        System.out.println(drl);

        KieSession kieSession=this.getKieSessionBySessionName("decision-rules");
        kieSession.fireAllRules();
        kieSession.dispose();
    }
}
